package GUI;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.LayoutManager;
import java.util.List;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import database.TableManager;
import database.TableManager.TableEnum;

public class GUI_page04_ProcessShipment extends JPanel {

	JLabel titleLabel;
	JButton returnButton;
	JLabel shipmentIDLabel;
	JTextField shipmentIDField;
	
	JTable table;
	JScrollPane scrollPane;
	
	JButton processButton;
	
	public GUI_page04_ProcessShipment() {
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		this.setBackground(Color.white);
		// title label
		titleLabel = new JLabel("Process Shipment", JLabel.CENTER);
		titleLabel.setVerticalTextPosition(JLabel.CENTER);
		
		titleLabel.setHorizontalTextPosition(JLabel.CENTER);
		titleLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
		titleLabel.setFont(new Font("Century Gothic", Font.BOLD, 20));
		titleLabel.setForeground(Color.gray);
        this.add(titleLabel);
        
        this.add(Box.createRigidArea(new Dimension(0,20)));

        // return button
        returnButton = GUI_AMSStoreMain.makeGrayWhiteButton("Cancel", Component.LEFT_ALIGNMENT);
        this.add(returnButton);
        
        this.add(Box.createRigidArea(new Dimension(0,10)));
        
        // shipment ID field
		shipmentIDLabel = GUI_AMSStoreMain.makeLeftAlignedGrayLabel("Shipment ID", 11);
		this.add(shipmentIDLabel);
		shipmentIDField = GUI_AMSStoreMain.makeLeftGrayTextField("", 80);
		this.add(shipmentIDField);
		
		this.add(Box.createRigidArea(new Dimension(0,10)));
		
		scrollPane = new JScrollPane(table);
		this.add(scrollPane);
		
		this.add(Box.createRigidArea(new Dimension(0,15)));
		
		// process button
        processButton = GUI_AMSStoreMain.makeGrayWhiteButton("Process Shipment", Component.LEFT_ALIGNMENT);
        processButton.setEnabled(false);
        processButton.setForeground(Color.RED);
        this.add(processButton);
	}
	
	public void populateTable(Object[] columnNames, Object[][] data){
		this.remove(scrollPane);
		
		if (columnNames == null || data == null)
			scrollPane = new JScrollPane();
		else
		{
			table = new JTable(data, columnNames);
			table.setPreferredScrollableViewportSize(new Dimension(400,70));
			table.setFillsViewportHeight(true);
			scrollPane = new JScrollPane(table);
		}
		this.add(scrollPane, 7);
	}
}
